

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>dtype - Boost.Python NumPy extension 1.0 documentation</title>
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/style.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '../',
          VERSION:     '1.0',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="top" title="Boost.Python NumPy extension 1.0 documentation" href="../index.html" />
    <link rel="up" title="Boost.Python NumPy extension Reference" href="index.html" />
    <link rel="next" title="ndarray" href="ndarray.html" />
    <link rel="prev" title="Boost.Python NumPy extension Reference" href="index.html" /> 
  </head>
  <body>
    <div class="header">
    <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
    "header">
      <tr>
        <td valign="top" width="300">
          <h3><a href="../index.html"><img 
          alt="C++ Boost" src="../_static/bpl.png" border="0"></a></h3>
        </td>

        <td >
          <h1 align="center"><a href="../index.html">(NumPy)</a></h1>
<!--          <h2 align="center">CallPolicies Concept</h2>-->
        </td>
	<td>
      <div id="searchbox" style="display: none">
        <form class="search" action="../search.html" method="get">
          <input type="text" name="q" size="18" />
          <input type="submit" value="Search" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
      </div>
      <script type="text/javascript">$('#searchbox').show(0);</script>
	</td>
      </tr>
    </table>
    </div>
    <hr/>
    <div class="content">
    <div class="navbar" style="text-align:right;">
      
      
      <a class="prev" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
      <a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
      <a class="next" title="ndarray" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
      
    </div>
      
  <div class="section" id="dtype">
<h1><a class="toc-backref" href="#id2">dtype</a></h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title first">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#dtype" id="id2">dtype</a><ul>
<li><a class="reference internal" href="#synopsis" id="id3">synopsis</a></li>
<li><a class="reference internal" href="#constructors" id="id4">constructors</a></li>
<li><a class="reference internal" href="#accessors" id="id5">accessors</a></li>
<li><a class="reference internal" href="#example-s" id="id6">Example(s)</a></li>
</ul>
</li>
</ul>
</div>
<p>A <a class="reference external" href="http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#data-type-objects-dtype">dtype</a> is an object describing the type of the elements of an ndarray</p>
<blockquote>
<div><code class="docutils literal"><span class="pre">&lt;boost/python/numpy/dtype.hpp&gt;</span></code> contains the method calls necessary to generate a python object equivalent to a numpy.dtype from builtin C++ objects, as well as to create custom dtypes from user defined types</div></blockquote>
<div class="section" id="synopsis">
<h2><a class="toc-backref" href="#id3">synopsis</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span></span><span class="k">namespace</span> <span class="n">boost</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">python</span>
<span class="p">{</span>
<span class="k">namespace</span> <span class="n">numpy</span>
<span class="p">{</span>

<span class="k">class</span> <span class="nc">dtype</span> <span class="o">:</span> <span class="k">public</span> <span class="n">object</span>
<span class="p">{</span>
  <span class="k">static</span> <span class="n">python</span><span class="o">::</span><span class="n">detail</span><span class="o">::</span><span class="n">new_reference</span> <span class="n">convert</span><span class="p">(</span><span class="n">object</span><span class="o">::</span><span class="n">object_cref</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="p">);</span>
<span class="k">public</span><span class="o">:</span>

  <span class="c1">// Convert an arbitrary Python object to a data-type descriptor object.</span>
  <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
  <span class="k">explicit</span> <span class="n">dtype</span><span class="p">(</span><span class="n">T</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="o">=</span><span class="nb">false</span><span class="p">);</span>

  <span class="c1">// Get the built-in numpy dtype associated with the given scalar template type.</span>
  <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span> <span class="k">static</span> <span class="n">dtype</span> <span class="n">get_builtin</span><span class="p">();</span>

  <span class="c1">// Return the size of the data type in bytes.</span>
  <span class="kt">int</span> <span class="nf">get_itemsize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
<span class="p">};</span>

<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="constructors">
<h2><a class="toc-backref" href="#id4">constructors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span></span><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span>
<span class="k">explicit</span> <span class="n">dtype</span><span class="p">(</span><span class="n">T</span> <span class="n">arg</span><span class="p">,</span> <span class="kt">bool</span> <span class="n">align</span><span class="o">=</span><span class="nb">false</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body"><p class="first"><code class="docutils literal"><span class="pre">T</span></code> must be either :</p>
<ul class="simple">
<li>a built-in C++ typename convertible to object</li>
<li>a valid python object or convertible to object</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Effects:</th><td class="field-body"><p class="first">Constructs an object from the supplied python object / convertible
to object / builtin C++ data type</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Throws:</th><td class="field-body"><p class="first last">Nothing</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-c++"><div class="highlight"><pre><span></span><span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="o">&gt;</span> <span class="k">static</span> <span class="n">dtype</span> <span class="n">get_builtin</span><span class="p">();</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Requirements:</th><td class="field-body">The typename supplied, <code class="docutils literal"><span class="pre">T</span></code> must be a builtin C++ type also supported by numpy</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Numpy dtype corresponding to builtin C++ type</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="accessors">
<h2><a class="toc-backref" href="#id5">accessors</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">get_itemsize</span><span class="p">()</span> <span class="k">const</span><span class="p">;</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">the size of the data type in bytes.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="example-s">
<h2><a class="toc-backref" href="#id6">Example(s)</a></h2>
<div class="highlight-c++"><div class="highlight"><pre><span></span><span class="k">namespace</span> <span class="n">p</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="p">;</span>
<span class="k">namespace</span> <span class="n">np</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">python</span><span class="o">::</span><span class="n">numpy</span><span class="p">;</span>

<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="o">::</span><span class="n">get_builtin</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;</span><span class="p">();</span>
<span class="n">p</span><span class="o">::</span><span class="n">tuple</span> <span class="n">for_custom_dtype</span> <span class="o">=</span> <span class="n">p</span><span class="o">::</span><span class="n">make_tuple</span><span class="p">(</span><span class="s">&quot;ha&quot;</span><span class="p">,</span><span class="n">dtype</span><span class="p">);</span>
<span class="n">np</span><span class="o">::</span><span class="n">dtype</span> <span class="n">custom_dtype</span> <span class="o">=</span> <span class="n">np</span><span class="o">::</span><span class="n">dtype</span><span class="p">(</span><span class="n">list_for_dtype</span><span class="p">);</span>
</pre></div>
</div>
</div>
</div>


    <div class="navbar" style="text-align:right;">
      
      
      <a class="prev" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/prev.png" alt="prev"/></a>
      <a class="up" title="Boost.Python NumPy extension Reference" href="index.html"><img src="../_static/up.png" alt="up"/></a>
      <a class="next" title="ndarray" href="ndarray.html"><img src="../_static/next.png" alt="next"/></a>
      
    </div>
    </div>
  </body>
</html>